<template>
	 <div class="sidebar">
        <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" theme="dark" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.childrens">
                    <el-submenu :index="item.nameEn">
                        <template slot="title"><i :class="item.icon"></i>{{ item.name }}</template>
                        <el-menu-item v-for="(subItem,i) in item.childrens" :key="i" :index="subItem.nameEn">{{ subItem.name }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.nameEn">
                        <i :class="item.icon"></i>{{ item.title }}
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
	import cmscommon from '@/utils/cmscommon'
	import interfaces from '@/interfaces'
	import Vue from 'Vue'
	 export default {
        data() {
            return {
                items: [
                 /*   {
                        icon: 'el-icon-menu',
                        nameEn: 'systemManage',
                        name: '系统管理',
                        childrens: [
                            {
                                nameEn: 'passwordUpdate',
                                name: '密码修改'
                            }
                        ]
                    }*/
                ]
            }
        },
		methods: {
			success(data) {
				console.log(data);
				if(data.data.code == 0) {
					this.items = data.data.data
				} else {
					this.$message({
						message: data.data.code + ":" + data.data.msg,
						type: 'error'
					})
				}
			},
			fail(data) {
				this.$message({
					message: data.response.data.status + ":" +
						data.response.data.error,
					type: 'error'
				})
			},
			searchOrgMenus: function() {
				console.log("获取后台管理系统的菜单信息");
				cmscommon.send({
					method: "GET",
					url: interfaces.searchOrgMenus.replace("{userCd}", localStorage.getItem('userCd')).replace("{orgCd}", localStorage.getItem('orgCd')).replace("{portalCd}","portal00000002"),
				}).then(this.success).catch(this.fail);

			}
		},
		created: function() {
			this.searchOrgMenus()
		},
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        }
    }
</script>

<style>
	    .sidebar{
        display: block;
        position: absolute;
        width: 250px;
        left: 0;
        top: 70px;
        bottom:0;
        background: #2E363F;
    }
    .sidebar > ul {
        height:100%;
    }
</style>